30.3.1 Connecting to a Neo4j Database
30.3.1 连接Neo4j数据库
你可以注入一个自动配置的Neo4jSession,Session,或Neo4jOperations实例,就像使用其他Spring Bean那样。该实例默认使用localhost:7474连接Neo4j服务器。下面的例子展示了怎么样注入一个Neo4j bean:
@Component
public class MyBean {
    private final Neo4jTemplate neo4jTemplate;
    @Autowired
    public MyBean(Neo4jTemplate neo4jTemplate) {
        this.neo4jTemplate = neo4jTemplate;
    }
    // ...
}
添加自己的org.neo4j.ogm.config.Configuration @Bean,你就能完全控制该配置了。同时,添加一个Neo4jOperations类型的@Bean可以禁用自动配置。
通过spring.data.neo4j.*属性可以配置使用的用户和凭证,如下所示:
spring.data.neo4j.uri=http://my-server:7474
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=secret